/**
 * 
 */
package org.vsg.stock.basic.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.vsg.common.biz.exception.ServiceException;
import org.vsg.stock.basic.domain.VolFigureDetails;
import org.vsg.stock.basic.persistence.VolFigureKlineDailyDao;
import org.vsg.stock.basic.service.VolFigureBusinussService;
import org.vsg.stock.basic.service.handler.VolFigureKlineDailyHandlerManager;
import org.vsg.stock.core.domain.StockDailyKLine;
import org.vsg.stock.core.persistence.StockDailyKLineDao;
import org.vsg.stock.core.persistence.StockInfoDao;

/**
 * @author Bill Vison
 * 
 *
 */
public class VolFigureBusinussServiceImpl implements VolFigureBusinussService {

	@Resource
	private VolFigureKlineDailyDao volFigureKlineDailyDao;
	
	@Resource
	private StockDailyKLineDao stockDailyKLineDao;
	
	@Resource
	private StockInfoDao stockInfoDao;
	
	
	@Autowired
	private VolFigureKlineDailyHandlerManager volFigureKlineDailyHandlerManager;
	
	/* (non-Javadoc)
	 * @see org.vsg.stock.basic.service.VolFigureBusinussService#updateOneStockFigureMapToKlineDaily(java.lang.String, java.util.Date, java.util.Date)
	 */
	@Override
	public void updateOneStockFigureMapToKlineDaily(String stockCode,
			Date startDate, Date endDate) throws ServiceException {
		// --- read one stock handle ---

		List<StockDailyKLine> stkDailyKLineList = stockDailyKLineDao.findStockLineByCycle(stockCode, startDate, endDate);

		volFigureKlineDailyHandlerManager.process( stkDailyKLineList , startDate ,  endDate);

		
	}
	

	
	
	
	@Override
	public void updateAllStockFigureMapToKlineDaily(Date startDate, Date endDate)
			throws ServiceException {
		
		List<String> allStkCodes = stockInfoDao.findAllRealCode();
		// --- update all source ---
		for (String code : allStkCodes) {
			updateOneStockFigureMapToKlineDaily(code , startDate , endDate);
		}
		
	}





	private void processVolFigureOfOverDouble(List<StockDailyKLine> periodStkDailyKLineList , Set<VolFigureDetails> volFigureDetailsSet) {
		
		StockDailyKLine stockDailyKline = null;
		for (int i = periodStkDailyKLineList.size() -1 ; i > 0 ; i--) {
			stockDailyKline = periodStkDailyKLineList.get(i);
			System.out.println( stockDailyKline.getDate() );
		}
		
		
	}
	
	
	
	

}
